package de.mafr.jsystest.matchers;

import net.sf.json.JSON;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import de.mafr.jsystest.json.JsonHttpResponse;


/**
 * Checks if a JSON HTTP response has the given body.
 */
public class HasJsonContent extends TypeSafeMatcher<JsonHttpResponse> {
	private final JSON content;

	public HasJsonContent(JSON content) {
		this.content = content;
	}

	@Override
	public boolean matchesSafely(JsonHttpResponse actual) {
		return actual.getContent().equals(content);
	}

	public void describeTo(Description description) {
		description.appendText("JSON content " + content + "");
	}
	
	@Factory
	public static <T> Matcher<JsonHttpResponse> content(JSON content) {
		return new HasJsonContent(content);
	}
}
